package com.mydemo.game.hireStage.random;

import com.mydemo.entity.Driver;
import com.mydemo.function.Level;

import java.util.Random;

public class DriverRandom {
    static Random random = new Random();
    public static final Driver randomDriver() {
        Driver driver = new Driver();
        driver.setName(NameRandom.getRandomName());
        driver.setDriverLicense(licenseRandom());
        driver.setExperience(experienceRandom());
        driver.setLevel(Level.calculateLevel(driver));
        driver.setSalary(Level.calculateSalary(driver));
        return driver;
    }

    private static final int experienceRandom(){
        final int LOW_RANGE_MAX = 500;
        final int MEDIUM_RANGE_MIN = 501;
        final int MEDIUM_RANGE_MAX = 5000;
        final int HIGH_RANGE_MIN = 5001;
        final int HIGH_RANGE_MAX = 50000;
        final double LOW_PROBABILITY = 0.70;
        final double MEDIUM_PROBABILITY = 0.20;
        final double HIGH_PROBABILITY = 0.10;
        double probability = random.nextDouble();

        if (probability < LOW_PROBABILITY) {
            return random.nextInt(LOW_RANGE_MAX);
        } else if (probability < LOW_PROBABILITY + MEDIUM_PROBABILITY) {
            return MEDIUM_RANGE_MIN + random.nextInt(MEDIUM_RANGE_MAX - MEDIUM_RANGE_MIN);
        } else {
            return HIGH_RANGE_MIN + random.nextInt(HIGH_RANGE_MAX - HIGH_RANGE_MIN);
        }
    }
    private static final String licenseRandom(){
        int num = random.nextInt(100)+1;
        if (num<=30){
            return "C1";
        }else {
            return "A1";
        }
    }
}
